package com.niit.controller.common;

import com.niit.model.Student;
import com.niit.model.Teacher;
import com.niit.service.StudentNewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Date;

/**
 * @author 王铭 20181620310021
 * #Date 2021/6/25 - 19:25
 */
@Controller
public class StudentController {


    StudentNewService studentNewService;

    @Autowired
    public void setTeacherNewService(StudentNewService studentNewService) {
        this.studentNewService = studentNewService;
    }

    @ModelAttribute("date")
    public Date date() {
        return new Date();
    }

    @GetMapping("main")
    public String main() {
        return "main";
    }

    @ModelAttribute("student")
    public void teacher(Model model) {
        Student student = new Student();
        student.setName("王铭");student.setId_student(2);
        student.setSex("男");
        student.setEmail("abc");
        model.addAttribute(student);
    }


    @GetMapping("login")
    public String login(Model model,String pwd ,String uname){
        model.addAttribute(studentNewService.login(uname,pwd));
        return "main";
    }


    @GetMapping("tasks")
    public String tasks(Model model,@ModelAttribute Student student){
        model.addAttribute(studentNewService.getTask(student));
        return "tasks";
    }

    @GetMapping("my-papers")
    public String myPapers(@ModelAttribute Student student,Model model){
        model.addAttribute(studentNewService.getMyPapers(student));
        return "my-papers";
    }

    @GetMapping("view-my-paper")
    public String viewMyPapers(Integer paperId,Model model){
        model.addAttribute(studentNewService.viewMyPaper(paperId));
        return "view-my-paper";
    }


    @GetMapping("my-class")
    public String myClass(Model model,@ModelAttribute Student student){
        model.addAttribute(studentNewService.myClass(student));
        return "my-class";
    }

    @GetMapping("quit-class")
    public String quitClass(Model model,Integer id,@ModelAttribute Student student){
        model.addAttribute(studentNewService.quitClass(id,student));
        return "my-class";
    }

    @GetMapping("join-class")
    public String getClass(Model model,Integer id,@ModelAttribute Student student){
        model.addAttribute(studentNewService.joinClass(id,student));
        return "join-class";
    }

    @GetMapping("to-join-class")
    public String getClass(Model model){
        return "join-class";
    }
}
